# -*- coding: utf-8 -*-


"""
抽象工厂模式

模式特点：提供一个创建一系列相关或相互依赖对象的接口，而无需指定它们的类。

程序实例：提供对不同的数据库访问的支持。

　　　　　IUser和IDepartment是两种不同的抽象产品，它们都有Access和SQL Server这两种不同的实现；IFactory是产生IUser和IDepartment的抽象工厂，根据具体实现（AccessFactory和SqlFactory）产生对应的具体的对象（CAccessUser与CAccessDepartment，或者CSqlUser与CSqlDepartment）。

代码特点：无
"""


class IUser(object):

    def get_user(self):
        pass

    def insert_user(self):
        pass


class IDepartment(object):

    def get_department(self):
        pass

    def insert_department(self):
        pass


class CAccessUser(IUser):

    def get_user(self):
        print "Access GetUser"

    def insert_user(self):
        print "Access InsertUser"


class CAccessDepartment(IDepartment):

    def get_department(self):
        print "Access GetDepartment"

    def insert_department(self):
        print "Access InsertDepartment"


class CSqlUser(IUser):

    def get_user(self):
        print "Sql GetUser"

    def insert_user(self):
        print "Sql InsertUser"


class CSqlDepartment(IDepartment):

    def get_department(self):
        print "Sql GetDepartment"

    def insert_department(self):
        print "Sql InsertDepartment"


class IFactory(object):
    def create_user(self):
        pass

    def create_department(self):
        pass


class AccessFactory(IFactory):

    def create_user(self):
        return CAccessUser()

    def create_department(self):
        return CAccessDepartment()


class SqlFactory(IFactory):

    def create_user(self):
        return CSqlUser()

    def create_department(self):
        return CSqlDepartment()

if __name__ == "__main__":
    factory = SqlFactory()
    user = factory.create_user()

    depart = factory.create_department()

    user.get_user()

    depart.get_department()

